package com.fei.config;

import lombok.SneakyThrows;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @SneakyThrows
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        File file = new File("");
        //获取项目上级目录
        File file1 = new File(file.getCanonicalPath());

        String path = "http://47.100.54.147:1111/data";

        //存放在工程根目录下
//        registry.addResourceHandler("/Music/Mv/**").addResourceLocations("file:"+file1+"/data/Music/Mv/");
//        registry.addResourceHandler("/Music/**").addResourceLocations("file:"+file1+"/data/Music/");
//        registry.addResourceHandler("/images/singer/**").addResourceLocations("file:"+file1+"/data/images/singer/");
//        registry.addResourceHandler("/Song List/**").addResourceLocations("file:"+file1+"/data/Song List/");
//        registry.addResourceHandler("/UserData/**").addResourceLocations("file:"+file1+"/data/UserData/");

        //使用服务器的
        registry.addResourceHandler("/Music/Mv/**").addResourceLocations(path + "/Music/Mv/");
        registry.addResourceHandler("/Music/**").addResourceLocations(path +"/Music/");
        registry.addResourceHandler("/images/singer/**").addResourceLocations(path + "/images/singer/");
        registry.addResourceHandler("/Song List/**").addResourceLocations(path + "/Song List/");
        registry.addResourceHandler("/UserData/**").addResourceLocations(path + "/UserData/");

    }
}
